package edu.gatech.cc.liam.core.rl.models;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;


public class JointConsecutiveNumberedActionIterator extends JointActionIterator implements Iterable<Action[]> {

	JointActionIterator theIter;
	
	public JointConsecutiveNumberedActionIterator(int numPlayers, int numActions) {
		super();
		ArrayList<Action> theActionSet = new ArrayList<Action>();
		for(int i=0; i<numActions; i++){
			theActionSet.add(new NumberedAction(i));
		}
		ArrayList<ArrayList<Action>> theActions = new ArrayList<ArrayList<Action>>();
		for(int i=0; i<numPlayers; i++){
			theActions.add(theActionSet);
		}
		this.initIterators(theActions);
	}
	
	public JointConsecutiveNumberedActionIterator(int numPlayers, int[] numActions) {
		super();
		assert numActions.length == numPlayers;
		ArrayList<ArrayList<Action>> theActions = new ArrayList<ArrayList<Action>>();
		for(int playerNum=0; playerNum<numPlayers; playerNum++){
			ArrayList<Action> theActionSet = new ArrayList<Action>();
			for(int i=0; i<numActions[playerNum]; i++){
				theActionSet.add(new NumberedAction(i));
			}
			theActions.add(theActionSet);
		}
		this.initIterators(theActions);
	}

	public static void main(String[] args) {
		for(Action[] anIter : new JointConsecutiveNumberedActionIterator(3,3)) {
			System.out.println(Arrays.asList(anIter));
		}
	}
	/***
	 * Returns a set of actions number 1 to numActions.
	 * @param numActions
	 * @return
	 */
	public static HashSet<Action> getConsecutiveActionSet(int numActions) {
		HashSet<Action> theActionSet = new HashSet<Action>();
		for(int i=0; i<numActions; i++){
			theActionSet.add(new NumberedAction(i));
		}
		return theActionSet;
	}
}
